package com.jicheng.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jicheng.Utils.ResultMess;
import com.jicheng.dto.app.AppDataHistoryDto;
import com.jicheng.dto.app.AppDateDto;
import com.jicheng.dto.user.UserDto;
import com.jicheng.ext.dto.PagingResult;
import com.jicheng.ext.dto.SearchPagingParams;
import com.jicheng.service.AppDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: AppDataController
 * @Description: TODO
 * @author: khz
 * @date: 2020年08月27日 16:41
 */

@Api(tags = "app-data(app数据对接)")
@RestController
@RequestMapping("/app-data")
public class AppDataController {

    @Autowired
    AppDataService appDataService;
    /**
     * 终端数据对接列表
     * @param searchPagingParams 查询条件参数
     * @return
     */
    @GetMapping("/dataList")
    @ApiOperation(value = "终端数据对接列表")
    public PagingResult<AppDataHistoryDto> dataList(SearchPagingParams searchPagingParams) {
        PageHelper.startPage(searchPagingParams.getPage(), searchPagingParams.getPageSize());
        List<AppDataHistoryDto> list = appDataService.dataList(searchPagingParams);
        PageInfo pageInfo = new PageInfo<>(list);
        PagingResult<AppDataHistoryDto> result = new PagingResult();
        result.setList(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());

        return result;
    }

    /**
     * 获取当前终端数据对接历史情况
     *
     * @param appId 终端id
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @GetMapping("/getAppDataHistory")
    @ApiOperation(value = "获取当前终端数据对接历史情况")
    public PagingResult<AppDateDto> getAppDataHistory(SearchPagingParams searchPagingParams, String startTime, String endTime,@RequestParam("appId") String appId) {
        PageHelper.startPage(searchPagingParams.getPage(), searchPagingParams.getPageSize());
        List<AppDateDto> list = appDataService.getAppDataHistory(appId,startTime,endTime);
        PageInfo pageInfo = new PageInfo<>(list);
        PagingResult<AppDateDto> result = new PagingResult();
        result.setList(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());
        return result;
    }
}
